package com.designoutput.ui.toolGroup
{
	import com.designoutput.enum.ToolType;
	import com.designoutput.icon.PdfIcon;
	import com.designoutput.icon.PsdIcon;
	import com.designoutput.icon.TifIcon;
	import com.designoutput.manager.ResourceManager;
	import com.designoutput.ui.TopToolBar;
	import com.designoutput.ui.controls.BarSplit;
	import com.designoutput.ui.controls.ToolButton;
	import com.designoutput.utils.Globals;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class ExtensionsGroup extends Sprite
	{
		private var topPanel:TopToolBar;
		private var pdf:ToolButton;
		private var psd:ToolButton;
		private var tif:ToolButton;
		
		internal var at:ToolButton;

		public function ExtensionsGroup(topPanel:TopToolBar)
		{
			this.topPanel = topPanel;
			build();
		}

		private function build():void
		{
			var split:BarSplit=new BarSplit();
			split.x=0;
			split.y=5;
			this.addChild(split);

			pdf=new ToolButton(ToolType.Pdf, new PdfIcon(0, 0), 1, 1);
			pdf.addEventListener(MouseEvent.MOUSE_DOWN, this.ToolMouseDown);
			pdf.addEventListener(MouseEvent.MOUSE_OVER, this.ToolMouseOver);
			pdf.addEventListener(MouseEvent.MOUSE_OUT, this.ToolMouseOut);
			pdf.x=10;
			pdf.y=5;
			this.addChild(pdf);

			psd=new ToolButton(ToolType.Psd, new PsdIcon(0, 0), 1, 1);
			psd.addEventListener(MouseEvent.MOUSE_DOWN, this.ToolMouseDown);
			psd.addEventListener(MouseEvent.MOUSE_OVER, this.ToolMouseOver);
			psd.addEventListener(MouseEvent.MOUSE_OUT, this.ToolMouseOut);
			psd.x=40;
			psd.y=5;
			this.addChild(psd);

			tif=new ToolButton(ToolType.Tif, new TifIcon(0, 0), 1, 1);
			tif.addEventListener(MouseEvent.MOUSE_DOWN, this.ToolMouseDown);
			tif.addEventListener(MouseEvent.MOUSE_OVER, this.ToolMouseOver);
			tif.addEventListener(MouseEvent.MOUSE_OUT, this.ToolMouseOut);
			tif.x=70;
			tif.y=5;
			this.addChild(tif);
		}
		
		
		/**
		 * Event listener for mouse down on tool buttons 
		 * @param evt
		 * 
		 */		
		private function ToolMouseDown(evt:MouseEvent):void
		{
			this.at=evt.currentTarget as ToolButton;
			this.at.Mark(true);
			this.at.addEventListener(MouseEvent.MOUSE_UP, ToolMouseUp);
		}
		
		private function ToolMouseUp(evt:MouseEvent):void
		{
			var btn:ToolButton=evt.currentTarget as ToolButton;
			if(btn.isMarked()){
				btn.Mark(false);
			}
		} 
		private function ToolMouseOver(evt:MouseEvent):void
		{
			var type:String=(evt.currentTarget as ToolButton).type;
			switch (type)
			{
				case ToolType.Pdf:
					Globals.designoutputCard.hover.setText(ResourceManager.getValue("rm_upload_pdf"));
					break;
				case ToolType.Psd:
					Globals.designoutputCard.hover.setText(ResourceManager.getValue("rm_upload_psd"));
					break;
				case ToolType.Tif:
					Globals.designoutputCard.hover.setText(ResourceManager.getValue("rm_upload_tif"));
					break;
				default:
					break;
			}
		}
		
		private function ToolMouseOut(evt:MouseEvent):void{
			Globals.designoutputCard.hover.hideEvent(evt);
			var btn:ToolButton=evt.currentTarget as ToolButton;
			if(btn.isMarked()){
				btn.Mark(false);
			}
		}
	}
}